package com.str.set;
import java.io.*;

public class IntSetTest {
	  
  public static void main(String[] args) throws IOException {
    BufferedReader stdin = new BufferedReader(
    	                   new InputStreamReader(System.in));    	                    	 	          
    IntSet thisSet = new IntSet();    
    IntSet thatSet = null;
    
    while (true) {
      System.out.println("-------------------------");
      System.out.println("     1. Clear");      
      System.out.println("     2. Add");    
      System.out.println("     3. Remove");
      System.out.println("     4. Contains");
      System.out.println("     5. Clone");
      System.out.println("     6. Union");      
      System.out.println("     7. Intersection");    
      System.out.println("     8. Difference");
      System.out.println("     9. Iquals");
      System.out.println("    10. Is subthisSet");
      System.out.print("\tEnter your choice(Enter to quit): ");
      
      String inputLine = stdin.readLine();
      if (inputLine.equals("")) {
        System.out.println("End of run.");
        System.exit(0);
      }        
      int choice = Integer.parseInt(inputLine);
      int i;   
      
      switch (choice) {
        case 1:
          System.out.println("Cleared.");
          thisSet.clear();
          break;

        case 2:
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          i = Integer.parseInt(inputLine);
          thisSet.add(i);
          break;

        case 3:
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          i = Integer.parseInt(inputLine);
          if (thisSet.contains(i)) {
            thisSet.remove(i);
            System.out.println(i + " has been deleted.");
          }
          else
            System.out.println("No found " + i);
          break;

        case 4:
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          i = Integer.parseInt(inputLine);
          if (thisSet.contains(i))
            System.out.println("Found " + i);
          else
            System.out.println("No found " + i);
          break;

        case 5:
          thatSet = (IntSet) thisSet.clone();
          break;
            
        case 6:
          System.out.println("UInion:");
          if (thatSet != null)
            thisSet.union(thatSet);
          break;
          
        case 7:
          System.out.println("Intersection:");
          if (thatSet != null)
            thisSet.intersection(thatSet);
          break;
   
        case 8:
          System.out.println("Difference:");
          if (thatSet != null)
            thisSet.difference(thatSet);
          break;
          
        case 9:
          if (thatSet != null)
            if (thisSet.equals(thatSet)) 
              System.out.println("This set is equal to that.");
            else            
              System.out.println("This set is not equal to that.");
          break;
          
        case 10:
          if (thatSet != null)
            if (thisSet.isSubset(thatSet)) 
              System.out.println("This set is a subset of that.");
            else            
              System.out.println("This set is not a subset of that.");
          break;
            
        default:
          System.out.println("Invalid choice.");
          continue;
      }
      
      System.out.println("This set:\n" + thisSet);
      System.out.println("Size: " + thisSet.size());
      if (thatSet != null) {
        System.out.println("That set:\n" + thatSet);
        System.out.println("Size: " + thatSet.size());
      }
    }
  }
}
